#include "comm.hpp"


int main()
{
    key_t k = ftok(PATH_NAME,PROJ_ID);
    if(k < 0)
    {
        perror("ftok");
        exit(1);
    }

    int shmid = shmget(k,SIZE,0);
    if(shmid < 0)
    {
        perror("shmget");
        exit(2);
    }


    char * shmaddr = (char*)shmat(shmid,nullptr,0);
    assert(shmaddr);

    // char a = 'a';
    // for(;a<='c';a++)
    // {
    //     snprintf(shmaddr,SIZE,"你好sever，我是client，我的pid是:%d,我目前的字符是:%c\n",getpid(),a);
    //     sleep(2);
    // }
    int fd = OpenFIFO(O_WRONLY);
    cout<<"client打开fifo成功"<<endl;
    while(1)
    {
        int s = read(0,shmaddr,SIZE);
        if(s < 0)
        {
            perror("read");
            exit(1);
        }
        shmaddr[s-1] = 0;
        Singal(fd);
        if(strcmp(shmaddr,"quit") == 0)break;
    }
    close(fd);
    int n = shmdt(shmaddr);
    assert(n != -1);
    (void)n;

    return 0;
}